package com.JDK.Lock;

import java.util.concurrent.CountDownLatch;

public class CountDown {



    public static void main(String[] args) {
        final CountDownLatch latch = new CountDownLatch(3);
        for(int i=0; i<3; i++){
            new Thread(() ->{
                try{
                    System.out.println(Thread.currentThread().getName() + " start");
                    Thread.sleep( 1500);
                    latch.countDown();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            },"Thread-" + i).start();
        }

        try{
            System.out.println("Thread : " + Thread.currentThread().getName() + " is waiting for children threads finish");
            latch.await();
            System.out.println("Thread : " + Thread.currentThread().getName() + "  start working now");
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
